﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.SysMan
{
    public partial class ListUserCheck : Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    if (roles_id == 1)//管理员
                    {
                        Bind();

                    }
                    else
                    {
                        Response.Redirect("../default.aspx");
                    }


                }
            }
           
        }

        //
        protected void btn_OK_Click(object sender, EventArgs e)
        {
            lcs.Model.user_check uc = new Model.user_check();

            uc.check_id = Convert.ToInt32(this.ddl_check.SelectedItem.Value);
            uc.cly_id = Convert.ToInt32(this.ddl_cly.SelectedItem.Value);

            if (new lcs.BLL.user_check().Add(uc) > 0)
            {
                Bind();
            }

        }

        private void Bind()
        {
            lcs.BLL.user u = new BLL.user();

            DataSet ds_check = u.GetUserRoles(" roles_id=4");//审核人
            DataSet ds_cly = u.GetUserRoles(" roles_id=3");//物料员

            this.ddl_check.DataSource = ds_check;
            this.ddl_check.DataTextField = "user_name";
            this.ddl_check.DataValueField = "user_id";
            this.ddl_check.DataBind();


            this.ddl_cly.DataSource = ds_cly;
            this.ddl_cly.DataTextField = "user_name";
            this.ddl_cly.DataValueField = "user_id";
            this.ddl_cly.DataBind();

            this.GridView1.DataSource = new lcs.BLL.user_check().GetList("");
            this.GridView1.DataBind();


        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_del")
            {
                if (e.CommandArgument != null)
                {
                    int user_check_id = Convert.ToInt32(e.CommandArgument.ToString());

                    lcs.BLL.user_check ucm = new BLL.user_check();

                    if (ucm.Delete(user_check_id))
                    {
                        Bind();
                    }
                }
            }
        }
    }
}